package com.asiainfo.ssm.execute.dao.impl;

import java.util.HashMap;

import com.asiainfo.ssm.execute.bo.BOExecCriticalPointPluginRelEngine;
import com.asiainfo.ssm.execute.dao.interfaces.ICriticalPointPluginRelDAO;
import com.asiainfo.ssm.execute.ivalues.IBOExecCriticalPointPluginRelValue;

public class CriticalPointPluginRelDAOImpl implements ICriticalPointPluginRelDAO {

	public void savePluginRel(IBOExecCriticalPointPluginRelValue value) throws Exception {

		if (value.getRelId() == 0) {
			value.setRelId(BOExecCriticalPointPluginRelEngine.getNewId().longValue());
		}
		BOExecCriticalPointPluginRelEngine.save(value);
	}

	public void deletePluginRel(long RelId) throws Exception {
		IBOExecCriticalPointPluginRelValue value = BOExecCriticalPointPluginRelEngine.getBean(RelId);
		value.delete();
		BOExecCriticalPointPluginRelEngine.save(value);

	}

	public void deletePluginRel(IBOExecCriticalPointPluginRelValue value) throws Exception {
		// TODO Auto-generated method stub
		value.delete();
		BOExecCriticalPointPluginRelEngine.save(value);
	}

	@Override
	public IBOExecCriticalPointPluginRelValue[] getExecCriticalPointPluginRels(long criticalPointId) throws Exception {
		String condition =IBOExecCriticalPointPluginRelValue.S_State +" = 1 AND "+IBOExecCriticalPointPluginRelValue.S_CriticalPointId + " =:criticalPointId";
		HashMap parameter = new HashMap<>();
		parameter.put("criticalPointId", criticalPointId);
		return BOExecCriticalPointPluginRelEngine.getBeans(condition, parameter);
	}

}
